@ECHO OFF
rem CONFIG START
rem -------------------------------------------------------------------------------
set RAR="%PROGRAMFILES%\winRar\rar.exe"
set NET="%PROGRAMFILES%\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"

set OPTS=dcplusplus.sln /build svnbuild
set CLEAN=dcplusplus.sln /clean svnbuild

set BETA="dcdm-beta-svn.rar"
set BETASOURCE="dcdm-beta-svn-src.rar"
set RARBIN=a -r -eH -ep1 -idp -inul -m3 %BETA% Temp\*.*
set RARSRC=a -r -eH -ep1 -idp -inul -m3 %BETASOURCE% ..\Temp\*.*
set RARINCLUDES=x -r -idp -inul "..\Docs and stuff\rars\for binary.rar"

rem CONFIG END
rem -------------------------------------------------------------------------------

IF NOT EXIST "%PROGRAMFILES%\WinRAR\Rar.exe" (
	echo "Winrar could not be found."
	pause
	goto:eof
)

IF NOT EXIST "%PROGRAMFILES%\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" (
	echo "visual studio could not be found."
	pause
	goto:eof
)

IF EXIST "..\..\app\DCDM-SVN.pdb" (
	del "..\..\app\*.pdb"
	ECHO Found Old PDB files.  Just deleted.
)

ECHO ------------------------------------------------------------------------
ECHO Cleaning solution...
cd..
cd..
rem %NET% %CLEAN%

ECHO ------------------------------------------------------------------------
ECHO Compiling solution in beta mode...
%NET% %OPTS%
ECHO Done!

ECHO ------------------------------------------------------------------------
ECHO updating Geo ip database...
cd "Docs and stuff\python"
updateGeoIP.py
cd..
cd..

ECHO ------------------------------------------------------------------------
ECHO Preparing copying
attrib +h /S /D .svn > nul
attrib +h /S /D _svn > nul

ECHO ------------------------------------------------------------------------
ECHO Make sure the path is clear
del /q %BETA% > nul
del /q %BETASOURCE% > nul
rd /s /q Temp > nul

ECHO ------------------------------------------------------------------------
ECHO copying files...
xcopy /Q /Y "Docs and stuff\docs\Changelog-post-psf8500.txt" Temp\ > nul
xcopy /Q /Y "Docs and stuff\docs\DCDM Help file.txt" Temp\ > nul
xcopy /Q /Y "Docs and stuff\misc\GeoIPCountryWhois.csv" Temp\ > nul
xcopy /Q /Y "Docs and stuff\misc\Example.xml" Temp\ > nul
xcopy /H /Q /Y App\DCDM-SVN.exe Temp\ > nul
xcopy /H /Q /Y App\*.pdb Temp\ > nul
xcopy /H /Q /Y App\lua-5.0.2.dll Temp\  > nul
xcopy /Q /Y scripts Temp\scripts\ > nul
attrib -h /s Temp\*.* > nul

ECHO ------------------------------------------------------------------------
ECHO adding includes
cd Temp
%RAR% %RARINCLUDES%
attrib -h /s *.*
cd..

ECHO ------------------------------------------------------------------------
ECHO packing executable...
%RAR% %RARBIN%

ECHO ------------------------------------------------------------------------
ECHO cleaning up
rd /s /q Temp > nul
attrib -h *.rar > nul

ECHO ------------------------------------------------------------------------
ECHO Preparing Source
attrib +h /S /D vc7 > nul
attrib +h /S /D App > nul
attrib +h /S /D bzip2 > nul
attrib +h /S /D lua-5.0.2 > nul
attrib +h /S /D luasql > nul
attrib +h /S /D pcre > nul
attrib +h /S /D res > nul
attrib +h /S /D stlport > nul
attrib +h /S /D wtl > nul
attrib +h /S /D zlib > nul
attrib +h /S /D "Docs and stuff\misc" > nul
attrib +h /S /D "Docs and stuff\python" > nul
attrib +h DCPlusPlus.ncb > nul
attrib +h DCPlusPlus.suo > nul
attrib +h client\*.user
attrib +h *.user > nul
attrib +h *.rar > nul
rd /s /q Temp > nul
xcopy /q /y /s "*.*" "..\Temp" > nul
xcopy /Q /Y "Docs and stuff\bats\RunMe-then-DeleteMe.bat" "..\Temp" > nul

ECHO ------------------------------------------------------------------------
ECHO packing source...
%RAR% %RARSRC%

ECHO ------------------------------------------------------------------------
ECHO cleaning up
rd /s /q ..\Temp > nul
attrib -h /S /D vc7 > nul
attrib -h /S /D App > nul
attrib -h /S /D bzip2 > nul
attrib -h /S /D lua-5.0.2 > nul
attrib -h /S /D luasql > nul
attrib -h /S /D pcre > nul
attrib -h /S /D res > nul
attrib -h /S /D stlport > nul
attrib -h /S /D wtl > nul
attrib -h /S /D zlib > nul
attrib -h /S /D "Docs and stuff\misc" > nul
attrib -h /S /D "Docs and stuff\python" > nul
attrib -h DCPlusPlus.ncb > nul
attrib -h DCPlusPlus.suo > nul
attrib -h client\*.user
attrib -h *.user > nul
attrib -h *.rar

ECHO ------------------------------------------------------------------------
ECHO finished!
pause